const peer =require('./peer-control')

peer.on('add-stream',(stream)=>{
  play(stream)
})


let video =document.getElementById('screen-video')
function play(stream){
  
  video.srcObject=stream
  video.onloadedmetadata=function(){
    video.play()
  }
}

window.onkeydown=function(e){
  
  let data={
    keyCode:e.keyCode,
    shift:e.shiftKey,
    meta:e.metaKey,
    ctrl:e.shiftKey,
    alt:e.altKey,
  }
  peer.emit('robot','key',data)
}

window.onmousedown=function(e){
  console.log(e)
  let data={}
  data.clientX=e.clientX
  data.clientY=e.clientY
  if(e.clientX<0||e.clientY<0){
    return
  }
  data.video={
    width:video.getBoundingClientRect().width,
    height:video.getBoundingClientRect().height,
  }
  peer.emit('robot','mouse',data)
}